package reference.weak;

import java.lang.ref.WeakReference;

public class WeakReferenceTest {
    public static void main(String[] args) {
        /**
         * 这样使用弱引用是没用的，因为new User()已经产生了一个引用user，也就是强引用，再把user放到WeakReference里面去没用
         * 应该这样 WeakReference<User> userWeakReference = new WeakReference<User>(new User("steak"));
         */
        WeakReference<User> userWeakReference = new WeakReference<>(new User("steak"));
        Object b = userWeakReference.get();
        System.out.println(userWeakReference.get());
        b = null;
        System.gc();
        System.out.println(userWeakReference.get());
        System.out.println(b);
    }
}
